/*
 * @Author: TC
 * @Date: 2025-06-19 16:41:53
 * @Last Modified by: TC
 * @Last Modified time: 2025-06-20 14:41:03
 */

import { app } from "db://assets/FrameWork/App";
import { nsSkillConfig } from "../../../Config/SkillConfig";
import { EntityBase } from "../EntityBase";
import { EntitySkill } from "../Propterty/EntitySkill";
import { nsBundleConst } from "../../../Const/BundleConst";
import { nsBulletInterface } from "../../Battle/Bullet/BulletInterface";
import { nsBulletHelper } from "../../../Module/Game/Helper/BulletHelper";

/**
 * 技能
 */
export class SkillItem {
    private _skillMgr: EntitySkill = null;
    private _owner: EntityBase = null;
    private _cfg: CfgInterface.ISkill = null;
    private _time = 0;

    constructor(skillMgr: EntitySkill, cfgId: number) {
        this._skillMgr = skillMgr;
        this._owner = this._skillMgr.entity;
        this._cfg = nsSkillConfig.getSkillCfg(cfgId);
        // app.log.log(this._cfg);
    }

    /**
     * 使用技能
     * @returns
     */
    public use(): void {
        if (!this._canExcute()) {
            // app.log.log("无法使用技能...");
            return;
        }
        this._excute();
        this._enterCd();
    }

    public tick(dt: number): void {
        this._time -= dt;
        if (this._time <= 0) {
            this._time = 0;
        }
    }

    /**
     * 是否在冷却中
     * @returns
     */
    private _inCd(): boolean {
        return this._time > 0;
    }

    /**
     * 进入冷却
     */
    private _enterCd(): void {
        this._time = this._cfg.cd;
    }

    /**
     * 执行技能
     */
    private _excute(): void {
        // app.log.log("技能执行");
        nsBulletHelper.createBullet(this._cfg, this._owner);
    }

    /**
     * 是否可执行
     */
    private _canExcute(): boolean {
        //冷却中
        if (this._inCd()) {
            return false;
        }
        return true;
    }
}
